package com.example.jl.bethinner.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.example.jl.bethinner.R;
import com.example.jl.bethinner.util.Switcher;
import com.example.jl.bethinner.view.AdvTextSwitcher;
import com.example.jl.bethinner.view.AutoTextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ButterKnifeActivity extends AppCompatActivity {

    @Bind(R.id.butter_knife)
    TextView butterKnife;
    @Bind(R.id.next)
    Button mBtnNext;
    @Bind(R.id.prev)
    Button mBtnPrev;
    @Bind(R.id.switcher02)
    AutoTextView mTextView02;
    @Bind(R.id.Advnext)
    Button Advnext;
    @Bind(R.id.Advprev)
    Button Advprev;
    @Bind(R.id.advTextSwitcher)
    AdvTextSwitcher advTextSwitcher;
    @Bind(R.id.Advstart)
    Button Advstart;
    @Bind(R.id.Advpause)
    Button Advpause;
    private Switcher switcher;

    @OnClick(R.id.butter_knife)
    void submit() {
        butterKnife.setText("我被点击了");
    }

    @OnClick(R.id.next)
    void btnNext() {
        mTextView02.next();
    }

    @OnClick(R.id.prev)
    void btnPrev() {
        mTextView02.previous();
    }

//    @OnClick(R.id.switcher02)
//    void mTextView02Click() {
//        Toast toast = Toast.makeText(this, "这是第" + mTextView02.getPosition(), Toast.LENGTH_SHORT);
//        toast.setGravity(Gravity.CENTER, 0, 0);
//        toast.setDuration(Toast.LENGTH_SHORT);
//        toast.show();
//    }

    @OnClick(R.id.Advnext)
    void advnext() {
        advTextSwitcher.next();
    }

    @OnClick(R.id.Advprev)
    void advprev() {
        advTextSwitcher.previous();
    }
    @OnClick(R.id.Advstart)
    void advsatrt() {
        switcher.start();
    } @OnClick(R.id.Advpause)
    void advpause() {
        switcher.pause();
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_butter_knife);
        ButterKnife.bind(this);
        butterKnife.setText("butterKnife");
        init();

    }

    private void init() {
        // TODO Auto-generated method stub
        mTextView02.setText("Hello world!");
        List<String> stringList = new ArrayList<>();
        for (int i = 0; i < 12; i++)
            stringList.add("这是" + i);

        mTextView02.setStringList(stringList);

        mTextView02.setOnItemTextClick(new AutoTextView.onItemTextClick() {
            @Override
            public void onItemClick(int position) {
                Toast.makeText(ButterKnifeActivity.this, "这是第" + mTextView02.getPosition(), Toast.LENGTH_SHORT).show();
            }
        });

        String[] texts = {"Anne: Great!", "Cathy: I do not think so.", "Jimmy: Cloning your repo...", "Aoi: This bug disappeared!"};
        advTextSwitcher = (AdvTextSwitcher) findViewById(R.id.advTextSwitcher);
        //Give them to AdvTextSwitcher
        advTextSwitcher.setTexts(texts);
        //Manually switch to the next text in the String array.
//        advTextSwitcher.next();
        //Switch to the previous one.
//        advTextSwitcher.previous();

        //Auto switch between texts every 5000ms.
         switcher = new Switcher(this, advTextSwitcher, 5000);

        //Pause
//        switcher.pause();
        //Or use switcher in only one line...
//        new Switcher(this).attach(advTextSwitcher).setDuration(5000).start();

        //Want to know which text is clicked?
        advTextSwitcher.setCallback(new AdvTextSwitcher.Callback() {
            @Override
            public void onItemClick(int position) {
                Toast.makeText(ButterKnifeActivity.this, "ITEM@" + position + " Clicked!", Toast.LENGTH_SHORT).show();
            }
        });

    }

}
